Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Objects /
Chapter 7 - View-Related Objects / About View Port Objects


View Port Objects and Windows

In most cases on the Macintosh, when your application draws to the screen it draws into a Macintosh window. (You do not need a window for offscreen drawing or when printing.) Most of the view ports you create, therefore, are in some way associated with windows. QuickDraw GX allows you to associate a view port with a window, tying it to the window and establishing it as the root of a view port hierarchy.

To attach a view port to a window, call the GXNewWindowViewPort function. This function sets up the view port so that drawing occurs only in the content area of the window (everything except for the title bar), effectively as if the view port's clip were equal to the window's visible region. When the user moves the window or changes its size, QuickDraw GX automatically moves the view port and adjusts its drawing limits to match the visible region. QuickDraw GX does not allow you to modify the clip or mapping of that view port.

If you add child view ports to the view port hierarchy, they are also moved as the window is moved. However, if the window is changed in shape, you need to adjust the clips of the child view ports to coincide with the new window dimensions.

Figure 7-9 shows a shape object drawn in two windows. In the window on the left,
the shape is drawn directly to the window's view port; in the window on the right, the shape is drawn to a child view port of the window's view port.

Figure 7-9 View ports in windows

One reason to draw only into a child view port is that it facilitates drawing tasks such as scrolling. Using a child view port helps to separate window management from content management when drawing. You use the parent view port for tracking window movement and visibility, and you manipulate the child view port's properties directly, without concern for the position or visibility of the parent view port. To implement scrolling, for example, you can follow these steps:

  1. Create a child view port for your window's view port.
  2. Draw your shapes to the child view port.
  3. Alter the child view port's mapping to reflect the translation caused by scrolling.

Figure 7-10 shows these steps schematically. Note that the scroll bars are part of the content area of the window, and adjusting them means drawing into the parent view port. Note also that the child view port clip is smaller than the content area of the window, so that drawing into it does not draw over the scroll bars.

Figure 7-10 Adjusting a child view port's mapping to handle scrolling

You need not adjust the child view port's clip after scrolling because the clip's position is not changed when the mapping is altered; you need to adjust the clip only when the dimensions of the child view port's drawing area are changed (such as when the window is resized). Remember also that you need to adjust the mapping of a child view port only when there is relative movement between the child view port and its parent; if the user simply moves the window, you do not need to adjust the child view port because QuickDraw GX handles this for you.

For information about how clipping and mapping interact, see the section "About Drawing, Coordinate Conversion, and Clipping" beginning on page 7-30.

For information about the GXNewWindowViewPort function, see the environment chapter of Inside Macintosh: QuickDraw GX Environment and Utilities. For an example that uses this function, see page 7-41.

Drawing is Not Restricted to Windows
QuickDraw GX view ports are not restricted to windows; you can
draw anywhere in a coordinate space. This feature makes it easy to
take complete control of a view device and draw anywhere on it. For example, you can support dragging of objects between windows in this way. On the other hand, because most QuickDraw GX applications
must share a view device with windows from other applications,
you typically want to restrict drawing to window content areas.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996